package linearstructure.queue.ordinary;

import linearstructure.queue.circle.CircleQueue;

import java.util.Scanner;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-05-23 14:02
 * @ Description : 数组模拟队列
 */
public class ArrayQueue
{
    public static void main(String[] args)
    {
        //Queue queue = new Queue(3);
        CircleQueue queue = new CircleQueue(3);
        char key = ' ';
        Scanner scanner = new Scanner(System.in);
        boolean loop = true;
        while (loop)
        {
            System.out.println("s(show):显示队列");
            System.out.println("e(exit):退出程序");
            System.out.println("a(add):添加数据到队列");
            System.out.println("g(get):从队列中取数据");
            System.out.println("h(head):获取队首数据");
            key = scanner.next().charAt(0);
            switch (key)
            {
                case 's':
                    queue.showQueue();
                    break;
                case 'e':
                    loop = false;
                    break;
                case 'a':
                    System.out.println("请输入添加的数据:");
                    int value = scanner.nextInt();
                    queue.addQueue(value);
                    break;
                case 'g':
                    try
                    {
                        int res = queue.getQueue();
                        System.out.printf("取出的数据为%d:\n",res);
                    }
                    catch (Exception e)
                    {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try
                    {
                        int res = queue.headQueue();
                        System.out.printf("队首的数据为%d\n:",res);
                    }
                    catch (Exception e)
                    {
                        System.out.println(e.getMessage());
                    }
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出!");

    }

}
